package com.ruoyi.recycle.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ruoyi.recycle.domain.AttractRecord;
import com.ruoyi.recycle.vo.AttractDataVO;
import com.ruoyi.recycle.vo.AttractRecordVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AttractRecordMapper extends BaseMapper<AttractRecord> {

    @Select("select shop_id, shop_name,salesman_name,salesman_id from attract_record ${ew.customSqlSegment}")
    List<AttractRecordVO> getAttractRecordListShop(@Param(Constants.WRAPPER) LambdaQueryWrapper<AttractRecord> wrapper);

    @Select("select client_id,client_name,salesman_name,salesman_id from attract_record ${ew.customSqlSegment}")
    List<AttractRecordVO> getAttractRecordListClient(@Param(Constants.WRAPPER) LambdaQueryWrapper<AttractRecord> wrapper);

    @Select("select salesman_id,sum(attract_count) as attractCount from attract_record ${ew.customSqlSegment} ")
    List<AttractRecord> countAttractBySalesman(@Param(Constants.WRAPPER) LambdaQueryWrapper<AttractRecord> wrapper);


    @Select("select client_id,sum(attract_count) as attractCount  from attract_record ${ew.customSqlSegment} ")
    List<AttractRecord> countAttractByClient(@Param(Constants.WRAPPER) LambdaQueryWrapper<AttractRecord> wrapper);


    @Select("select count(client_id) from attract_record where merchant_id = ${merchantId}")
    int countMerchantClient(@Param("merchantId") Long merchantId);


    @Select("select sum(attract_count) as attractCount, DATE_FORMAT(create_time,'%Y-%m-%d') as date from attract_record ${ew.customSqlSegment} ")
    List<AttractDataVO> sumAttractRecordByTime(@Param(Constants.WRAPPER) LambdaQueryWrapper<AttractRecord> attractRecordWrapper);

    @Select("select sum(attract_count) from attract_record ${ew.customSqlSegment}")
    int sum(@Param(Constants.WRAPPER) LambdaQueryWrapper<AttractRecord> lambdaQuery);
}
